<!-- 审核管理-采购审核 -->
<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <span>固定资产采购申请审核</span>
      </div>
      <el-table v-loading="loading" :data="list" row-key="id">
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column prop="odd" label="申请单号"></el-table-column>
        <el-table-column prop="name" label="固定资产名称"></el-table-column>
        <el-table-column prop="model" label="规格型号"></el-table-column>
        <el-table-column prop="number" label="采购数量"></el-table-column>
        <el-table-column prop="auditState" label="审核状态" width="100">
          <template slot-scope="scope">
            <dict-tag
              :options="dict.type.audit_state"
              :value="scope.row.auditState"
            />
          </template>
        </el-table-column>
        <el-table-column label="申请时间" align="center" prop="createTime">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="250px">
          <template slot-scope="scope">
            <!-- <el-button size="mini" type="text" icon="el-icon-view"
              >查看
            </el-button> -->
            <el-button
              style="color: #67c23a"
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="submitForm('通过', scope.row)"
              >通过
            </el-button>
            <el-button
              style="color: #f56c6c"
              size="mini"
              type="text"
              icon="el-icon-close"
              @click="submitForm('驳回', scope.row)"
              >驳回
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-share"
              @click="
                () => {
                  $router.push({
                    path: '/base-log/log/purchase',
                    query: { id: scope.row.id },
                  });
                }
              "
            >
              日志
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="queryParams.total > 0"
        :total="queryParams.total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import { page, edit } from "@/api/prod/purchase/plan";

export default {
  name: "Plan",
  dicts: ["audit_state"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 表格树数据
      list: [],
      // 请求参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stateList: ["待审核", "审核通过"],
        // 总数
        total: 0,
      },
    };
  },
  created() {
    this.getList();
  },

  methods: {
    /** 查询采购计划列表 */
    getList() {
      this.loading = true;
      page(this.queryParams).then((response) => {
        this.list = response.data;
        this.queryParams.total = response.info.total;
        this.loading = false;
      });
    },

    /** 提交按钮 */
    submitForm(action, { id }) {
      if(action == '驳回') {
        this.$prompt('请输入驳回原因', {}).then(({ value }) => {
          edit({ id, action, message:value }).then((response) => {
            this.$modal.msgSuccess("提交成功");
            this.getList();
          });
        });
      } else {
        edit({ id, action }).then((response) => {
          this.$modal.msgSuccess("提交成功");
          this.getList();
        });
      }
    },
  },
};
</script>

<style>
</style>